package cn.ecut.dispatcher;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @author lujiapeng
 * @className DispatcherInclude
 * @description TODO
 * @date 2020/9/14 8:46
 **/
@WebServlet("/include")
public class DispatcherInclude extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.setCharacterEncoding("UTF-8");
        response.setContentType("text/html; charset=UTF-8");

        PrintWriter writer = response.getWriter();
        writer.write("我是外部的 Servlet 01 ");

        RequestDispatcher requestDispatcher = request.getRequestDispatcher("/innerServlet");
        requestDispatcher.include( request , response );

        writer.write("我是外部的 Servlet 02 ");
    }
}
